file1 = open('titles.txt')
file2 = open('pagerank.txt')
output = open('titlesPR','w')


titlesDict = {}
titles = []

for line in file1:
    title = line.split('##')[0].strip() 
    titles.append( title )
    titlesDict[ title ] = line.strip()
    
for line in file2:
    title = line.split('##')[0].strip() 
    if title in titlesDict:
        titlesDict[title] += ' ## ' + ( line.split('##')[1].strip() )

for elem in titles:
    output.write( titlesDict[elem] + '\n' )

output.close()
    
    

